<?php
/**
 * Модель currency
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Модель currency
 *
 */
class ModelCurrency extends Model {
	
	const TABLE				= 'currency';
	const F_CURRENCY_ID  	= 'currency_id';
	const F_NAME  	= 'name';
	const F_VALUE  	= 'value';
	const F_TITLE  	= 'title';
	const F_DESCRIPTION  	= 'description';
	const F_LANG_ID  	= 'lang_id';
			
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='currency';
		$this->id_field=array(self::F_CURRENCY_ID);
		$this->fields=array(
		self::TABLE.DOT.self::F_CURRENCY_ID=> new Field($this,self::F_CURRENCY_ID,self::TABLE,array(
				'auto'=>true,
				'important'=>true,
				'lenght'=>1)),
		self::TABLE.DOT.self::F_NAME=> new Field($this,self::F_NAME,self::TABLE,array(
				'important'=>true,
				'lenght'=>10,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_VALUE=> new Field($this,self::F_VALUE,self::TABLE,array(
				'auto'=>true,
				'lenght'=>6)),
		self::TABLE.DOT.self::F_TITLE=> new Field($this,self::F_TITLE,self::TABLE,array(
				'important'=>true,
				'lenght'=>30,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_DESCRIPTION=> new Field($this,self::F_DESCRIPTION,self::TABLE,array(
				'important'=>true,
				'lenght'=>70,
				'type'=>Field::TYPE_STRING)),
		self::TABLE.DOT.self::F_LANG_ID=> new Field($this,self::F_LANG_ID,self::TABLE,array(
				'auto'=>true,
				'lenght'=>2,
				'join_table'=>'lang'))		);
	}

	//получаем калюту по id магазина
	public function loadByShop($shop_id){
		return import('model.shop',true)->loadOne(false,array(
				ModelCurrency::TABLE.DOT.ModelCurrency::F_NAME,
				ModelCurrency::TABLE.DOT.ModelCurrency::F_VALUE
			),array(
			'where' => ModelShop::TABLE.DOT.ModelShop::F_SHOP_ID."=".$shop_id,
			'join'=>array(
					array('table'=>ModelCurrency::TABLE, 'key'=>ModelCurrency::F_CURRENCY_ID, 'join_table'=>ModelShop::TABLE, 'join_field'=>ModelShop::F_CURRENCY_ID)
				)
			 )
		);
	}
}
